What is mutator method?

A mutator method is a type of method in object-oriented programming that is used to modify the state of an object. Mutator methods are often referred to as "setter" methods because they are used to set the values of the attributes of an object.

In general, mutator methods take a parameter that represents the new value to be assigned to a specific attribute of an object. These methods typically do not have a return value, as their main purpose is to modify the state of the object.

Mutator methods are often used in combination with accessor methods, which are used to retrieve the values of the attributes of an object. Together, accessor and mutator methods provide a way to control access to the state of an object, allowing for encapsulation and data abstraction in object-oriented programming.

It is important to note that mutator methods should be carefully designed to ensure that the object's state remains consistent and that any necessary validations are performed to maintain the integrity of the object's data.